package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Issue;
import com.cskaoyan.bean.ItemsListVO;
import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商场管理的通用问题
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    @RequestMapping("list")
    public BaseRespVo issueList(Integer page, Integer limit, String sort, String order, String question){
        ItemsListVO issueListVO = issueService.queryIssueList(page, limit, sort, order, question);
        return BaseRespVo.ok(issueListVO);
    }

    @RequestMapping("create")
    public BaseRespVo createIssue(@RequestBody Issue issue){
        Issue newIssue = issueService.createIssue(issue);
        return BaseRespVo.ok(newIssue);
    }

    @RequestMapping("update")
    public BaseRespVo updateIssue(@RequestBody Issue issue){
        Issue updateIssue = issueService.updateIssue(issue);
        return BaseRespVo.ok(updateIssue);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteIssue(@RequestBody Issue issue){
        int delete = issueService.deleteIssue(issue);
        if (delete == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除问题失败");
    }
}
